﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace RecruitmentProcessSystem
{
    public partial class frmViewVacancy : Form
    {
        String conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;

        public frmViewVacancy()
        {
            InitializeComponent();
        }

        private void frmViewVacancy_Load(object sender, EventArgs e)
        {
            ds = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd = new SqlCommand("Select * from Vacancy", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Vacancy");
            btnReport.DataSource = ds.Tables[0];
            conn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
            if (cbxSearch.SelectedItem.ToString() == "Tìm kiếm theo tên")
            {
                ds.Tables[0].DefaultView.RowFilter = "vname like\'%" + txtName.Text + "%\'";
            }
            else if (cbxSearch.SelectedItem.ToString() == "Tìm kiếm theo bộ phận")
            {
                ds.Tables[0].DefaultView.RowFilter = "vdepartment like\'%" + txtName.Text + "%\'";
            }
            }
            catch
            {
                ds.Tables[0].DefaultView.RowFilter = "vname like\'%" + txtName.Text + "%\'";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            frmReportVacancy frm = new frmReportVacancy();
            frm.Show();
        }
    }
}
